package com.woniuxy.lab.woniu_lab.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.lab.woniu_lab.exception.WebException;
import com.woniuxy.lab.woniu_lab.model.Order;
import com.woniuxy.lab.woniu_lab.dao.OrderDao;
import com.woniuxy.lab.woniu_lab.model.User;
import com.woniuxy.lab.woniu_lab.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.lab.woniu_lab.service.UserService;
import com.woniuxy.lab.woniu_lab.service.dto.chargeDto.MyOrderDto;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 消费记录表 服务实现类
 * </p>
 *
 * @author Silas
 * @since 2023-03-15
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderDao, Order> implements OrderService {

    @Resource
    private UserService userService;

    @Resource
    private OrderDao orderDao;

    @Override
    public IPage<MyOrderDto> queryMyOrder(int page, int size, Integer userId) {
        //判断用户是否存在
        userService.assertUser();
        //查询操作
        IPage<Order> iPage = new Page<>(page, size);
        IPage<Order> OrderIPage = page(iPage, new QueryWrapper<Order>().eq("user_id", userId));
        //转换OrderIPage为dto
        IPage<MyOrderDto> MyOrderDtoIPage = OrderIPage.convert(o->{
                MyOrderDto m =  new MyOrderDto();
                BeanUtil.copyProperties(o,m);
                return m;
            });

        return MyOrderDtoIPage;
    }




}
